﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using VIT.DataHelper.DataAccess;

namespace VIT.Wedding.Modules.ContentDetail
{
    public partial class ContentDetail : VIT.Web.UI.VITModule
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var lang = Session["language"].ToString();
            int sId = Convert.ToInt32(Params["sId"]);
            var product = VITData.GetObject<Product>(c => c.Id == sId);
            var productLang = VITData.GetObject<Products_Language>(c => c.ProductId == sId && c.LanguageId == lang);
            if (product != null)
            {
                lblName.Text = productLang.Title;
                var cat = VITData.GetObject<Category_Language>(c => c.CategoryId == product.CategoryId);
                if (cat != null)
                {
                    lblType.Text = cat.Title;
                }
                lblDescription.Text = productLang.Brief;
                lblPrice.Text = product.Price == 0 ? "Liên hệ" : product.Price.ToString("0,0");

                var result = VITData.GetQuery<Product_Image>(c => c.ProductId == sId).ToArray();

                rptProductImage.DataSource = result;
                rptProductImage.DataBind();
                rptProductImageJava.DataSource = result;
                rptProductImageJava.DataBind();

                // cập nhật lượt xem
                product.Views += 1;
                VITData.UpdateObject(c => c.Id == product.Id, product);
            }
            
        }
    }
}